package org.main.userprovider.controller;

import org.main.bean.POJO.PAddress;
import org.main.userprovider.Dao.PAddressDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * By： 土豆菌
 * 2019-02-19 14:31
 */

@RestController
@RequestMapping("/addres")
public class AddresController {
    @Autowired
    private PAddressDao pAddressDao;

    @RequestMapping("/query/{id}")
    public List<PAddress> getOne(@PathVariable("id") int userId){
        return pAddressDao.getAlls(userId);
    }

    @RequestMapping("/updata/{id}/{people}/{phone}/{address}/{addressxx}/{moren}")
    public String updata(@PathVariable("id") int id, @PathVariable("people") String people, @PathVariable("phone") int phone, @PathVariable("address") String address, @PathVariable("addressxx") String addressxx, @PathVariable("moren") int moren){
        String msg ="成功";
        PAddress pAddress=pAddressDao.getOne(id);
        pAddress.setPeople(people);
        pAddress.setPhone(phone);
        pAddress.setAddress(address);
        pAddress.setAddressxx(addressxx);
        pAddress.setMoren(moren);
        try {
            pAddressDao.save(pAddress);
        } catch (Exception e) {
            msg = "失败";
        }
        return msg;
    }

    @RequestMapping("/insert/{people}/{phone}/{address}/{addressxx}/{moren}/{userId}")
    public String insert(@PathVariable("people") String people,@PathVariable("phone") int phone,@PathVariable("address") String address,@PathVariable("addressxx") String addressxx,@PathVariable("moren") int moren,@PathVariable("userId") int userId){
        String msg ="成功";
        PAddress pAddress=new PAddress(people,phone,address,addressxx,moren,userId);

        try {
            pAddressDao.save(pAddress);
        } catch (Exception e) {
            msg = "失败";
        }
        return msg;
    }

}
